const parseWithErrorHandle = (v, fn, key) => {
  let rec;
  try {
    rec = fn(v);
  } catch (e) {
    console.log(`${v}不是合法的${key}`);
  }
  return rec;
};

export default {
  set(key, value) {
    localStorage.setItem(key, JSON.stringify(value));
  },
  get(key) {
    return parseWithErrorHandle(localStorage.getItem(key), JSON.parse, key);
  },
  remove(key) {
    localStorage.removeItem(key);
  },
  clear() {
    localStorage.clear();
  },
};
